/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
 var reverseStr = function(s, k) {
  let arr = s.split('')
  const reverse = (arr,left,right)=>{
    while(left < right){
      let t = arr[left]
      arr[left] = arr[right]
      arr[right] = t
      left++
      right--
    }
  }
  let n = 1
  while(n * k <= arr.length){
    reverse(arr,(n-1)*k,n*k - 1)
    n = n + 2
  }
  if((n-1)*k < arr.length){
    reverse(arr,(n-1)*k,arr.length-1)
  }
  return arr.join('')
};